package com.ymatou.iapi.trading.operate2.parameter.enums;

import java.util.HashMap;
import java.util.Map;

/**
 */
public enum BusinessTypeEnum {

	CANCEL_ORDER(1, "trading_cancelorder"),

	ORDER_PAY(2, "trading_orderpay"),

	ORDER_POST_PAY(3, "trading_postpay"),

	CONFIRM_RECEIVE(4, "trading_confirmreceive"),

	AUTO_CONFIRM_RECEIVE_ADVANCE_NOTICE(5, "trading_cfmreceiveadvannotice"),

	ACCEPT_ORDER(6, "trading_acceptorder"),

	ACCEPT_ORDER_CALLBACK(7, ""),

	APPLY_FOR_POST_PAY(8, "trading_applyforpostpay"),

	CANCEL_POST_PAY(9, "trading_cancelpostpay"),

	SELLER_DISPATCHED(10, "trading_dispatched"),

	SELLER_REFUND(11, "trading_sellerrefund"),

	//CHANGE_ORDER_DISCOUNT(12, "trading_commonmq"),

	DELAY_RECEIVE(13, "trading_delayreceive"),

	CREATE_ORDER(14, "trading_createorder"),

	CHANGE_ORDER_ADDRESS(15, "trading_commonmq"),

	AUTO_CONFIRM_RECEIVE(16, "trading_autoconfirmreceive"),

	SALES_REFUND(17, "trading_salesrefund"),

	AUTO_CANCEL_ORDER(18, "trading_autocancelorder"),

	ADD_PRODUCT_STOCK(19, "trading_addproductstock"),

	LOCK_SKU_STOCK(20, "trading_lockskustock"),

	TIMER_NOT_PAY(23, "trading_timernotpay"),

	SYNC_ORDER_CMD(24, "trading_syncordercmd"),

	SALES_REFUND_SUCCESS(25, "trading_salesrefundsuccess"),

	DOMESTIC_DELIVERY(26, "domesticdelivery"),

	ORDER_NOT_PAY(27, "trading_ordernotpay"),

	ORDER_DELETED(28, "orderdeleted"),

	ADD_REFUND_STOCK(29, "trading_addrefundstock"),

	ORDER_ROLLBACK_DISPATCH(30, "trading_rollbackdispatch"),

	ORDER_ON_PAID(31, "trading_onpaid"),

	/**
	 * 已接单48小时未发货通知
	 */
	NO_DISPATCHED(32, "trading_nodispatched"),

	CREATE_ORDER_GROUP(33, "trading_createordergroup"),

	PAYMENT_PAID(34, "payment_paid"),

	PAYMENT_RETRY(35, "payment_retry"),

	RECEIVE_SETTLED(100, "trading_receivesettled");

	private static final Map<Integer, BusinessTypeEnum> maps = new HashMap<>();

	static {
		for (BusinessTypeEnum e : BusinessTypeEnum.values()) {
			maps.put(e.getCode(), e);
		}
	}

	int code;
	String messageCode;

	BusinessTypeEnum(int code, String messageCode) {
		this.code = code;
		this.messageCode = messageCode;
	}

	public static BusinessTypeEnum getEnum(int code) {
		try {
			return maps.get(code);
		} catch (NumberFormatException e) {
			return null;
		}
	}

	public static BusinessTypeEnum getByMessageCode(String messageCode) {
		for (BusinessTypeEnum result : BusinessTypeEnum.values()) {
			if (result.getMessageCode().equalsIgnoreCase(messageCode)) {
				return result;
			}
		}
		return null;
	}

	public int getCode() {
		return code;
	}

	public String getMessageCode() {
		return messageCode;
	}

}
